import Vue from 'vue'
import { Message } from 'element-ui';
let host = ''
if(process.env.NODE_ENV === "development"){
	host = 'http://127.0.0.1:8090/'
}else{
	host = 'http://114.115.129.182:8090/'
}
function request(url, method, params, urlParams){

  return new Promise((resolve)=>{
  	Vue.axios[method](host + url, params ,{params:urlParams}).then(res=>{
	  	if(res.status === 200 && res.data.code === 200){
	  		resolve(res.data.data) 
	  	}else{
	  		Message.error(res.data.data);
	  	}
	  }).catch(()=>{
	  		Message.error("系统错误");
	  })
  }) 
}
 
function get(url,params,urlParams) {
  return request(url, 'get', params, urlParams)
}
 
function post (url,params,urlParams) {
  return request(url, 'post', params, urlParams)
}
 
export default {
  request,
  get,
  post,
  host
}